package com.kantboot.business.talent.web.admin.controller;

import com.kantboot.business.talent.domain.simple.UserAccountSimple;
import com.kantboot.business.talent.repository.UserAccountSimpleRepository;
import com.kantboot.global.exception.GlobalException;
import com.kantboot.util.common.result.RestResult;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/business-talent-web/admin/userAccountSimple")
public class UserAccountSimpleControllerOfAdmin {

    @Resource
    private UserAccountSimpleRepository repository;

    @RequestMapping("/saveOfAdd")
    public RestResult<Object> saveOfAdd(@RequestBody UserAccountSimple entity){
        entity.setId(null);
        if (repository.countByPhoneAreaCodeAndPhone(entity.getPhoneAreaCode(), entity.getPhone()) > 0) {
            throw GlobalException.userAccount.PHONE_EXIST;
        }
        // 查询手机号是否重复
        UserAccountSimple save = repository.save(entity);
        return RestResult.success(save,"saveSuccess","添加成功");
    }

}
